#include "OwerTeam.h"
#include "AITeamState.h"
using namespace std;
OwerTeam::OwerTeam(void)
{
}

OwerTeam::~OwerTeam(void)
{
}
void OwerTeam::Init()
{
	cout<<"Begin Init OwnerTeam\n";
	//Init default pos for team
	myTeam = new AIPlayer[5];
	myTeam[0].SetTypePlayer(GOALKEEPER);
	myTeam[1].SetTypePlayer(RIGHTPLAYER);
	myTeam[2].SetTypePlayer(LEFTPLAYER);
	myTeam[3].SetTypePlayer(CENTERPLAYER);
	myTeam[4].SetTypePlayer(ATTACKPLAYER);
	for(int i = 0; i < 5; i++)
		myTeam[i].SetDefaultPos();
	cout<<"End Init OwnerTeam\n";
}
void OwerTeam::Update()
{
	bool isCanGetBall = false;
	switch(AITeamState::GetInstance()->GetState())
	{
		case ATTACKSTATE:
			std::cout<<"ATTACKSTATE!\n";
			Attack();
			break;
		case DEFENCESTATE:
			std::cout<<"DEFENCESTATE!\n";
			Defence();
			break;
		case INDENTIFYSTATE:
			std::cout<<"INDENTIFYSTATE!\n";
			Defence();
			break;
	};

	for (int i = 0; i < 5; i++)
	{
		//myTeam[i].Update();
	}
}

int OwerTeam::PositionOfType(PLAYERTYPE type)
{
	int i;
	for (i = 0; i < 5; i++)
	{
		if (myTeam[i].GetTypePlayer() == type)
		{
			return i;
		}
	}
	return -1;
}

void OwerTeam::Attack()
{
	int iClosed = AITeamState::GetInstance()->closestPeople;
	int positionOfType[8];
	bool attackInLeft;
	bool haveDefence;

	int countDef = 0;
	int countAttack = 0;
	int countCenter = 0;
	int i = 0;
	PLAYERTYPE typeClosed = myTeam[iClosed].typePlayer;

	countDef = 0;
	countAttack = 0;
	countCenter = 0;
	for (i = 0; i < 8; i++)
	{
		positionOfType[i] = PositionOfType((PLAYERTYPE)i);
	}

	if (positionOfType[LEFTPLAYER] > 0)
	{
		countDef++;
	}
	if (positionOfType[RIGHTPLAYER] > 0)
	{
		countDef++;
	}
	if (positionOfType[DEFENCEPLAYER] > 0)
	{
		countDef++;
	}
	if (positionOfType[ATTACKPLAYERLEFT] > 0)
	{
		countAttack++;
	}
	if (positionOfType[ATTACKPLAYERRIGHT] > 0)
	{
		countAttack++;
	}
	if (positionOfType[ATTACKPLAYER] > 0)
	{
		countAttack++;
	}
	if (positionOfType[CENTERPLAYER] > 0)
	{
		countCenter++;
	}
	if (countAttack + countDef == 3 && ( countAttack == 1 || countDef == 1) && countCenter == 1)
	{
	}
	else
	{
		std::cout<<"ATTACK START----"<<countAttack<<"--"<<countCenter<<"--"<<countDef<<std::endl;
	}
	if (typeClosed == LEFTPLAYER)
	{
		if (positionOfType[ATTACKPLAYERLEFT] > 0 && myTeam[iClosed].PassTo(myTeam[positionOfType[ATTACKPLAYERLEFT]].GetPos())) 
		{
			for (i = 4; i > 0; i--)
			{
				if (i == iClosed)
				{
					continue;
				}
				if (myTeam[i].typePlayer == ATTACKPLAYERLEFT)
				{
					myTeam[i].GetBall();
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYERRIGHT)
				{
					myTeam[i].MoveTo(ATTACKPLAYERRIGHT, myTeam[positionOfType[ATTACKPLAYERLEFT]].GetPos());
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYER)
				{
					myTeam[i].MoveTo(ATTACKPLAYERRIGHT, myTeam[positionOfType[ATTACKPLAYERLEFT]].GetPos());
					myTeam[i].typePlayer = ATTACKPLAYERRIGHT;
					if (positionOfType[ATTACKPLAYERRIGHT] < 0)
						positionOfType[ATTACKPLAYERRIGHT] = i;
					positionOfType[ATTACKPLAYER] = -1;
				}
				else if (myTeam[i].typePlayer == CENTERPLAYER)
				{
					if (countAttack == 1)
					{
						myTeam[i].MoveTo(ATTACKPLAYER, myTeam[positionOfType[ATTACKPLAYERLEFT]].GetPos());
						myTeam[i].typePlayer = ATTACKPLAYER;
						if (positionOfType[ATTACKPLAYER] < 0)
							positionOfType[ATTACKPLAYER] = i;
						positionOfType[CENTERPLAYER] = -1;
						countAttack++;
					}
					else
					{
						myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[ATTACKPLAYERLEFT]].GetPos());
					}
				}
				else if (myTeam[i].typePlayer == RIGHTPLAYER)
				{
					if (countDef == 2)
					{
						myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[ATTACKPLAYERLEFT]].GetPos());
						myTeam[i].typePlayer = CENTERPLAYER;
						if (positionOfType[CENTERPLAYER] < 0)
							positionOfType[CENTERPLAYER] = i;
						positionOfType[RIGHTPLAYER] = -1;
						countDef--;
					}
				}
				else if (myTeam[i].typePlayer == DEFENCEPLAYER)
				{
					if (countDef == 2)
					{
						myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[ATTACKPLAYERLEFT]].GetPos());
						myTeam[i].typePlayer = CENTERPLAYER;
						if (positionOfType[CENTERPLAYER] < 0)
							positionOfType[CENTERPLAYER] = i;
						positionOfType[DEFENCEPLAYER] = -1;
						countDef--;
					}
				}
			}
		}
		else if (positionOfType[ATTACKPLAYER] > 0 && myTeam[iClosed].PassTo(myTeam[positionOfType[ATTACKPLAYER]].GetPos())) 
		{
			for (i = 4; i > 0; i--)
			{
				if (i == iClosed)
				{
					continue;
				}
				if (myTeam[i].typePlayer == ATTACKPLAYERLEFT)
				{
					myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[ATTACKPLAYER]].GetPos());
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYERRIGHT)
				{
					myTeam[i].MoveTo(ATTACKPLAYERRIGHT, myTeam[positionOfType[ATTACKPLAYER]].GetPos());
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYER)
				{
					myTeam[i].GetBall();
				}
				else if (myTeam[i].typePlayer == CENTERPLAYER)
				{
					if (countAttack == 1)
					{
						myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[ATTACKPLAYER]].GetPos());
						myTeam[i].typePlayer = ATTACKPLAYERLEFT;
						if (positionOfType[ATTACKPLAYERLEFT] < 0)
							positionOfType[ATTACKPLAYERLEFT] = i;
						positionOfType[CENTERPLAYER] = -1;
						countAttack++;
					}
					else
					{
						myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[ATTACKPLAYER]].GetPos());
					}
				}
				else if (myTeam[i].typePlayer == RIGHTPLAYER)
				{
					myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[ATTACKPLAYER]].GetPos());
					myTeam[i].typePlayer = CENTERPLAYER;
					if (positionOfType[CENTERPLAYER] < 0)
						positionOfType[CENTERPLAYER] = i;
					positionOfType[RIGHTPLAYER] = -1;
					countDef--;
				}
				else if (myTeam[i].typePlayer == DEFENCEPLAYER)
				{
					myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[ATTACKPLAYER]].GetPos());
					myTeam[i].typePlayer = CENTERPLAYER;
					if (positionOfType[CENTERPLAYER] < 0)
						positionOfType[CENTERPLAYER] = i;
					positionOfType[DEFENCEPLAYER] = -1;
					countDef--;
				}
			}
			
		}
		else if (positionOfType[CENTERPLAYER] > 0 && myTeam[iClosed].PassTo(myTeam[positionOfType[CENTERPLAYER]].GetPos())) 
		{
			for (i = 4; i > 0; i--)
			{
				if (i == iClosed)
				{
					continue;
				}
				if (myTeam[i].typePlayer == ATTACKPLAYERLEFT)
				{
					myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[CENTERPLAYER]].GetPos());
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYERRIGHT)
				{
					if (positionOfType[ATTACKPLAYERLEFT] < 0 && positionOfType[ATTACKPLAYER] < 0)
					{
						myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[CENTERPLAYER]].GetPos());
						myTeam[i].typePlayer = ATTACKPLAYERLEFT;
						positionOfType[ATTACKPLAYERLEFT] = i;
						positionOfType[ATTACKPLAYERRIGHT] = -1;
					}
					else
					{
						myTeam[i].MoveTo(ATTACKPLAYERRIGHT, myTeam[positionOfType[CENTERPLAYER]].GetPos());
					}
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYER)
				{
					if (positionOfType[ATTACKPLAYERLEFT] < 0)
					{
						myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[CENTERPLAYER]].GetPos());
						myTeam[i].typePlayer = ATTACKPLAYERLEFT;
						if (positionOfType[ATTACKPLAYERLEFT] < 0)
							positionOfType[ATTACKPLAYERLEFT] = i;
						positionOfType[ATTACKPLAYER] = -1;
					}
					else
					{
						myTeam[i].MoveTo(ATTACKPLAYERRIGHT, myTeam[positionOfType[CENTERPLAYER]].GetPos());
						myTeam[i].typePlayer = ATTACKPLAYERRIGHT;
						if (positionOfType[ATTACKPLAYERRIGHT] < 0)
							positionOfType[ATTACKPLAYERRIGHT] = i;
						positionOfType[ATTACKPLAYER] = -1;
					}
				}
				else if (myTeam[i].typePlayer == CENTERPLAYER)
				{
					myTeam[i].GetBall();
				}
				else if (myTeam[i].typePlayer == RIGHTPLAYER)
				{
					myTeam[i].MoveTo(ATTACKPLAYERRIGHT, myTeam[positionOfType[CENTERPLAYER]].GetPos());
					myTeam[i].typePlayer = ATTACKPLAYERRIGHT;
					if (positionOfType[ATTACKPLAYERRIGHT] < 0)
						positionOfType[ATTACKPLAYERRIGHT] = i;
					positionOfType[RIGHTPLAYER] = -1;
					countAttack++;
					countDef--;
				}
				else if (myTeam[i].typePlayer == DEFENCEPLAYER)
				{
					myTeam[i].MoveTo(ATTACKPLAYERRIGHT, myTeam[positionOfType[CENTERPLAYER]].GetPos());
					myTeam[i].typePlayer = ATTACKPLAYERRIGHT;
					if (positionOfType[ATTACKPLAYERRIGHT] < 0)
						positionOfType[ATTACKPLAYERRIGHT] = i;
					positionOfType[DEFENCEPLAYER] = -1;
					countAttack++;
					countDef--;
				}
			}
			
		}
		else if (positionOfType[RIGHTPLAYER] > 0 && myTeam[iClosed].PassTo(myTeam[positionOfType[RIGHTPLAYER]].GetPos())) 
		{
			for (i = 4; i > 0; i--)
			{
				if (i == iClosed)
				{
					continue;
				}
				if (myTeam[i].typePlayer == ATTACKPLAYERLEFT)
				{
					myTeam[i].MoveTo(ATTACKPLAYERRIGHT, myTeam[positionOfType[RIGHTPLAYER]].GetPos());
					myTeam[i].typePlayer = ATTACKPLAYERRIGHT;
					if (positionOfType[ATTACKPLAYERRIGHT] < 0)
						positionOfType[ATTACKPLAYERRIGHT] = i;
					positionOfType[ATTACKPLAYERLEFT] = -1;
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYERRIGHT)
				{
					myTeam[i].MoveTo(ATTACKPLAYERRIGHT, myTeam[positionOfType[RIGHTPLAYER]].GetPos());
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYER)
				{
					myTeam[i].MoveTo(ATTACKPLAYERRIGHT, myTeam[positionOfType[RIGHTPLAYER]].GetPos());
					myTeam[i].typePlayer = ATTACKPLAYERRIGHT;
					if (positionOfType[ATTACKPLAYERRIGHT] < 0)
						positionOfType[ATTACKPLAYERRIGHT] = i;
					positionOfType[ATTACKPLAYER] = -1;
				}
				else if (myTeam[i].typePlayer == CENTERPLAYER)
				{
					myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[RIGHTPLAYER]].GetPos());
				}
				else if (myTeam[i].typePlayer == RIGHTPLAYER)
				{
					myTeam[i].GetBall();
				}
			}
			
		}
		else
		{
			if (positionOfType[ATTACKPLAYERLEFT] > 0)
				myTeam[iClosed].SetTarget(myTeam[positionOfType[ATTACKPLAYERLEFT]].GetPos());
			else if (positionOfType[ATTACKPLAYERRIGHT] > 0)
				myTeam[iClosed].SetTarget(myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos());
			else if (positionOfType[ATTACKPLAYER] > 0)
				myTeam[iClosed].SetTarget(myTeam[positionOfType[ATTACKPLAYER]].GetPos());
			myTeam[iClosed].SetFoce(k_kick_foce);
			myTeam[iClosed].SetAction(KICK);
		}
	}
	else if (typeClosed == DEFENCEPLAYER)
	{
		if (positionOfType[ATTACKPLAYERLEFT] > 0)
			myTeam[iClosed].SetTarget(myTeam[positionOfType[ATTACKPLAYERLEFT]].GetPos());
		else if (positionOfType[ATTACKPLAYERRIGHT] > 0)
			myTeam[iClosed].SetTarget(myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos());
		else if (positionOfType[ATTACKPLAYER] > 0)
			myTeam[iClosed].SetTarget(myTeam[positionOfType[ATTACKPLAYER]].GetPos());
		myTeam[iClosed].SetFoce(k_kick_foce);
		myTeam[iClosed].SetAction(KICK);
	}
	else if (typeClosed == RIGHTPLAYER)
	{
		if (positionOfType[ATTACKPLAYERRIGHT] > 0 && myTeam[iClosed].PassTo(myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos())) 
		{
			for (i = 4; i > 0; i--)
			{
				if (i == iClosed)
				{
					continue;
				}
				if (myTeam[i].typePlayer == ATTACKPLAYERLEFT)
				{
					myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos());
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYERRIGHT)
				{
					myTeam[i].GetBall();
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYER)
				{
					myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos());
					myTeam[i].typePlayer = ATTACKPLAYERLEFT;
					if (positionOfType[ATTACKPLAYERLEFT] < 0)
						positionOfType[ATTACKPLAYERLEFT] = i;
					positionOfType[ATTACKPLAYER] = -1;
				}
				else if (myTeam[i].typePlayer == CENTERPLAYER)
				{
					if (countAttack == 1)
					{
						myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos());
						myTeam[i].typePlayer = ATTACKPLAYERLEFT;
						if (positionOfType[ATTACKPLAYERLEFT] < 0)
							positionOfType[ATTACKPLAYERLEFT] = i;
						positionOfType[CENTERPLAYER] = -1;
						countAttack++;
					}
					else
					{
						myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos());
					}
				}
				else if (myTeam[i].typePlayer == LEFTPLAYER)
				{
					myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos());
					myTeam[i].typePlayer = CENTERPLAYER;
					if (positionOfType[CENTERPLAYER] < 0)
						positionOfType[CENTERPLAYER] = i;
					positionOfType[LEFTPLAYER] = -1;
					countDef--;
				}
				else if (myTeam[i].typePlayer == DEFENCEPLAYER)
				{
					myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos());
					myTeam[i].typePlayer = CENTERPLAYER;
					if (positionOfType[CENTERPLAYER] < 0)
						positionOfType[CENTERPLAYER] = i;
					positionOfType[DEFENCEPLAYER] = -1;
					countDef--;
				}
			}
		}
		else if (positionOfType[ATTACKPLAYER] > 0 && myTeam[iClosed].PassTo(myTeam[positionOfType[ATTACKPLAYER]].GetPos())) 
		{
			for (i = 4; i > 0; i--)
			{
				if (i == iClosed)
				{
					continue;
				}
				if (myTeam[i].typePlayer == ATTACKPLAYERLEFT)
				{
					myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[ATTACKPLAYER]].GetPos());
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYERRIGHT)
				{
					myTeam[i].MoveTo(ATTACKPLAYERRIGHT, myTeam[positionOfType[ATTACKPLAYER]].GetPos());
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYER)
				{
					myTeam[i].GetBall();
				}
				else if (myTeam[i].typePlayer == CENTERPLAYER)
				{
					if (countAttack == 1)
					{
						myTeam[i].MoveTo(ATTACKPLAYERRIGHT, myTeam[positionOfType[ATTACKPLAYER]].GetPos());
						myTeam[i].typePlayer = ATTACKPLAYERRIGHT;
						if (positionOfType[ATTACKPLAYERRIGHT] < 0)
							positionOfType[ATTACKPLAYERRIGHT] = i;
						positionOfType[CENTERPLAYER] = -1;
						countAttack++;
					}
					else
					{
						myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[ATTACKPLAYER]].GetPos());
					}
				}
				else if (myTeam[i].typePlayer == LEFTPLAYER)
				{
					myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[ATTACKPLAYER]].GetPos());
					myTeam[i].typePlayer = CENTERPLAYER;
					if (positionOfType[CENTERPLAYER] < 0)
						positionOfType[CENTERPLAYER] = i;
					positionOfType[LEFTPLAYER] = -1;
					countDef--;
				}
				else if (myTeam[i].typePlayer == DEFENCEPLAYER)
				{
					myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[ATTACKPLAYER]].GetPos());
					myTeam[i].typePlayer = CENTERPLAYER;
					if (positionOfType[CENTERPLAYER] < 0)
						positionOfType[CENTERPLAYER] = i;
					positionOfType[DEFENCEPLAYER] = -1;
					countDef--;
				}
			}
		}
		else if (positionOfType[CENTERPLAYER] > 0 && myTeam[iClosed].PassTo(myTeam[positionOfType[CENTERPLAYER]].GetPos())) 
		{
			for (i = 4; i > 0; i--)
			{
				if (i == iClosed)
				{
					continue;
				}
				if (myTeam[i].typePlayer == ATTACKPLAYERLEFT)
				{
					if (positionOfType[ATTACKPLAYERRIGHT] < 0 && positionOfType[ATTACKPLAYER] < 0)
					{
						myTeam[i].MoveTo(ATTACKPLAYERRIGHT, myTeam[positionOfType[CENTERPLAYER]].GetPos());
						myTeam[i].typePlayer = ATTACKPLAYERRIGHT;
						if (positionOfType[ATTACKPLAYERRIGHT] < 0)
							positionOfType[ATTACKPLAYERRIGHT] = i;
						positionOfType[ATTACKPLAYERLEFT] = -1;
					}
					else
					{
						myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[CENTERPLAYER]].GetPos());
					}
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYERRIGHT)
				{
					myTeam[i].MoveTo(ATTACKPLAYERRIGHT, myTeam[positionOfType[CENTERPLAYER]].GetPos());
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYER)
				{
					if (positionOfType[ATTACKPLAYERRIGHT] < 0)
					{
						myTeam[i].MoveTo(ATTACKPLAYERRIGHT, myTeam[positionOfType[CENTERPLAYER]].GetPos());
						myTeam[i].typePlayer = ATTACKPLAYERRIGHT;
						if (positionOfType[ATTACKPLAYERRIGHT] < 0)
							positionOfType[ATTACKPLAYERRIGHT] = i;
						positionOfType[ATTACKPLAYER] = -1;
					}
					else
					{
						myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[CENTERPLAYER]].GetPos());
						myTeam[i].typePlayer = ATTACKPLAYERLEFT;
						if (positionOfType[ATTACKPLAYERLEFT] < 0)
							positionOfType[ATTACKPLAYERLEFT] = i;
						positionOfType[ATTACKPLAYER] = -1;
					}
				}
				else if (myTeam[i].typePlayer == CENTERPLAYER)
				{
					myTeam[i].GetBall();
				}
				else if (myTeam[i].typePlayer == LEFTPLAYER)
				{
					myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[CENTERPLAYER]].GetPos());
					myTeam[i].typePlayer = ATTACKPLAYERLEFT;
					if (positionOfType[ATTACKPLAYERLEFT] < 0)
						positionOfType[ATTACKPLAYERLEFT] = i;
					positionOfType[LEFTPLAYER] = -1;
					countAttack++;
					countDef--;
				}
				else if (myTeam[i].typePlayer == DEFENCEPLAYER)
				{
					myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[CENTERPLAYER]].GetPos());
					myTeam[i].typePlayer = ATTACKPLAYERLEFT;
					if (positionOfType[ATTACKPLAYERLEFT] < 0)
						positionOfType[ATTACKPLAYERLEFT] = i;
					positionOfType[DEFENCEPLAYER] = -1;
					countAttack++;
					countDef--;
				}
				
			}
		}
		else if (positionOfType[LEFTPLAYER] > 0 && myTeam[iClosed].PassTo(myTeam[positionOfType[LEFTPLAYER]].GetPos())) 
		{
			for (i = 4; i > 0; i--)
			{
				if (i == iClosed)
				{
					continue;
				}
				if (myTeam[i].typePlayer == ATTACKPLAYERLEFT)
				{
					myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[LEFTPLAYER]].GetPos());
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYERRIGHT)
				{
					myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[LEFTPLAYER]].GetPos());
					myTeam[i].typePlayer = ATTACKPLAYERLEFT;
					if (positionOfType[ATTACKPLAYERLEFT] < 0)
						positionOfType[ATTACKPLAYERLEFT] = i;
					positionOfType[ATTACKPLAYERRIGHT] = -1;
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYER)
				{
					myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[LEFTPLAYER]].GetPos());
					myTeam[i].typePlayer = ATTACKPLAYERLEFT;
					if (positionOfType[ATTACKPLAYERLEFT] < 0)
						positionOfType[ATTACKPLAYERLEFT] = i;
					positionOfType[ATTACKPLAYER] = -1;
				}
				else if (myTeam[i].typePlayer == CENTERPLAYER)
				{
					myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[LEFTPLAYER]].GetPos());
				}
				else if (myTeam[i].typePlayer == LEFTPLAYER)
				{
					myTeam[i].GetBall();
				}
				
			}
			
		}
		else
		{
			if (positionOfType[ATTACKPLAYERLEFT] > 0)
				myTeam[iClosed].SetTarget(myTeam[positionOfType[ATTACKPLAYERLEFT]].GetPos());
			else if (positionOfType[ATTACKPLAYERRIGHT] > 0)
				myTeam[iClosed].SetTarget(myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos());
			else if (positionOfType[ATTACKPLAYER] > 0)
				myTeam[iClosed].SetTarget(myTeam[positionOfType[ATTACKPLAYER]].GetPos());
			myTeam[iClosed].SetFoce(k_kick_foce);
			myTeam[iClosed].SetAction(KICK);
		}
	}
	else if (typeClosed == CENTERPLAYER)
	{
		if (positionOfType[ATTACKPLAYER] > 0 && myTeam[iClosed].PassTo(myTeam[positionOfType[ATTACKPLAYER]].GetPos()))
		{
			for (i = 4; i > 0; i--)
			{
				if (i == iClosed)
				{
					continue;
				}
				if (myTeam[i].typePlayer == ATTACKPLAYERLEFT)
				{
					myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[ATTACKPLAYER]].GetPos());
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYERRIGHT)
				{
					myTeam[i].MoveTo(ATTACKPLAYERRIGHT, myTeam[positionOfType[ATTACKPLAYER]].GetPos());
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYER)
				{
					myTeam[i].GetBall();
				}
				else if (myTeam[i].typePlayer == LEFTPLAYER)
				{
					if (countDef <= 1)
					{
						myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[ATTACKPLAYER]].GetPos());
						myTeam[i].typePlayer = DEFENCEPLAYER;
						positionOfType[DEFENCEPLAYER] = i;
						positionOfType[LEFTPLAYER] = -1;
					}
					else
					{
						myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[ATTACKPLAYER]].GetPos());
						myTeam[i].typePlayer = ATTACKPLAYERLEFT;
						positionOfType[ATTACKPLAYERLEFT] = i;
						positionOfType[LEFTPLAYER] = -1;
						countAttack++;
						countDef--;
					}
				}
				else if (myTeam[i].typePlayer == RIGHTPLAYER)
				{
					if (countDef <= 1)
					{
						myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[ATTACKPLAYER]].GetPos());
						myTeam[i].typePlayer = DEFENCEPLAYER;
						positionOfType[DEFENCEPLAYER] = i;
						positionOfType[RIGHTPLAYER] = -1;
					}
					else
					{
						myTeam[i].MoveTo(ATTACKPLAYERRIGHT, myTeam[positionOfType[ATTACKPLAYER]].GetPos());
						myTeam[i].typePlayer = ATTACKPLAYERRIGHT;
						positionOfType[ATTACKPLAYERRIGHT] = i;
						positionOfType[RIGHTPLAYER] = -1;
						countAttack++;
						countDef--;
					}
				}
				else if (myTeam[i].typePlayer == DEFENCEPLAYER)
				{
					myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[ATTACKPLAYER]].GetPos());
				}
				
			}
			
		}
		else if (positionOfType[ATTACKPLAYERLEFT] > 0 && myTeam[iClosed].PassTo(myTeam[positionOfType[ATTACKPLAYERLEFT]].GetPos()))
		{
			for (i = 4; i > 0; i--)
			{
				if (i == iClosed)
				{
					continue;
				}
				if (myTeam[i].typePlayer == ATTACKPLAYERLEFT)
				{
					myTeam[i].GetBall();
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYERRIGHT)
				{
					myTeam[i].MoveTo(ATTACKPLAYERRIGHT, myTeam[positionOfType[ATTACKPLAYERLEFT]].GetPos());
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYER)
				{
					myTeam[i].MoveTo(ATTACKPLAYERRIGHT, myTeam[positionOfType[ATTACKPLAYERLEFT]].GetPos());
					myTeam[i].typePlayer = ATTACKPLAYERRIGHT;
					positionOfType[ATTACKPLAYERRIGHT] = i;
					positionOfType[ATTACKPLAYER] = -1;
				}
				else if (myTeam[i].typePlayer == LEFTPLAYER)
				{
					myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[ATTACKPLAYERLEFT]].GetPos());
					myTeam[i].typePlayer = DEFENCEPLAYER;
					if (positionOfType[DEFENCEPLAYER] < 0)
					{
						positionOfType[DEFENCEPLAYER] = i;
					}
					positionOfType[LEFTPLAYER] = -1;
				}
				else if (myTeam[i].typePlayer == RIGHTPLAYER)
				{
					if (countDef == 1)
					{
						myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[ATTACKPLAYERLEFT]].GetPos());
						myTeam[i].typePlayer = DEFENCEPLAYER;
						positionOfType[DEFENCEPLAYER] = i;
						positionOfType[RIGHTPLAYER] = -1;
					}
					else
					{
						myTeam[i].MoveTo(ATTACKPLAYERRIGHT, myTeam[positionOfType[ATTACKPLAYERLEFT]].GetPos());
						myTeam[i].typePlayer = ATTACKPLAYERRIGHT;
						positionOfType[ATTACKPLAYERRIGHT] = i;
						positionOfType[RIGHTPLAYER] = -1;
						countAttack++;
						countDef--;
					}
				}
				else if (myTeam[i].typePlayer == DEFENCEPLAYER)
				{
					if (countDef == 1)
					{
						myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[ATTACKPLAYERLEFT]].GetPos());
					}
					else
					{
						myTeam[i].MoveTo(ATTACKPLAYERRIGHT, myTeam[positionOfType[ATTACKPLAYERLEFT]].GetPos());
						myTeam[i].typePlayer = ATTACKPLAYERRIGHT;
						positionOfType[ATTACKPLAYERRIGHT] = i;
						positionOfType[DEFENCEPLAYER] = -1;
						countAttack++;
						countDef--;
					}
				}
				
			}
			
		}
		else if (positionOfType[ATTACKPLAYERRIGHT] > 0 && myTeam[iClosed].PassTo(myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos()))
		{
			for (i = 4; i > 0; i--)
			{
				if (i == iClosed)
				{
					continue;
				}
				if (myTeam[i].typePlayer == ATTACKPLAYERLEFT)
				{
					myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos());
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYERRIGHT)
				{
					myTeam[i].GetBall();
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYER)
				{
					myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos());
					myTeam[i].typePlayer = ATTACKPLAYERLEFT;
					positionOfType[ATTACKPLAYERLEFT] = i;
					positionOfType[ATTACKPLAYER] = -1;
				}
				else if (myTeam[i].typePlayer == LEFTPLAYER)
				{
					if (countDef == 1)
					{
						myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos());
						myTeam[i].typePlayer = DEFENCEPLAYER;
						positionOfType[DEFENCEPLAYER] = i;
						positionOfType[LEFTPLAYER] = -1;
					}
					else
					{
						myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos());
						myTeam[i].typePlayer = ATTACKPLAYERLEFT;
						positionOfType[ATTACKPLAYERLEFT] = i;
						positionOfType[LEFTPLAYER] = -1;
						countAttack++;
						countDef--;
					}
				}
				else if (myTeam[i].typePlayer == RIGHTPLAYER)
				{
					myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos());
					myTeam[i].typePlayer = DEFENCEPLAYER;
					if (positionOfType[DEFENCEPLAYER] < 0)
					{
						positionOfType[DEFENCEPLAYER] = i;
					}
					positionOfType[RIGHTPLAYER] = -1;
				}
				else if (myTeam[i].typePlayer == DEFENCEPLAYER)
				{
					if (countDef == 1)
					{
						myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos());
					}
					else
					{
						myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos());
						myTeam[i].typePlayer = ATTACKPLAYERLEFT;
						positionOfType[ATTACKPLAYERLEFT] = i;
						positionOfType[DEFENCEPLAYER] = -1;
						countAttack++;
						countDef--;
					}
				}
				
			}
			
		}
		else if (positionOfType[LEFTPLAYER] > 0 && myTeam[iClosed].PassTo(myTeam[positionOfType[LEFTPLAYER]].GetPos()))
		{
			for (i = 4; i > 0; i--)
			{
				if (i == iClosed)
				{
					continue;
				}
				if (myTeam[i].typePlayer == ATTACKPLAYERLEFT)
				{
					myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[LEFTPLAYER]].GetPos());
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYERRIGHT)
				{
					if (countAttack == 2)
					{
						myTeam[i].MoveTo(RIGHTPLAYER, myTeam[positionOfType[LEFTPLAYER]].GetPos());
						myTeam[i].typePlayer = RIGHTPLAYER;
						positionOfType[RIGHTPLAYER] = i;
						positionOfType[ATTACKPLAYERRIGHT] = -1;
						countAttack--;
						countDef++;
					}
					else
					{
						myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[LEFTPLAYER]].GetPos());
						myTeam[i].typePlayer = ATTACKPLAYERLEFT;
						positionOfType[ATTACKPLAYERLEFT] = i;
						positionOfType[ATTACKPLAYERRIGHT] = -1;
					}
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYER)
				{
					if (countAttack == 2
						&& positionOfType[ATTACKPLAYERLEFT] >= 0)
					{
						myTeam[i].MoveTo(RIGHTPLAYER, myTeam[positionOfType[LEFTPLAYER]].GetPos());
						myTeam[i].typePlayer = RIGHTPLAYER;
						positionOfType[RIGHTPLAYER] = i;
						positionOfType[ATTACKPLAYER] = -1;
						countAttack--;
						countDef++;
					}
					else
					{
						myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[LEFTPLAYER]].GetPos());
						myTeam[i].typePlayer = ATTACKPLAYERLEFT;
						positionOfType[ATTACKPLAYERLEFT] = i;
						positionOfType[ATTACKPLAYER] = -1;
					}
				}
				else if (myTeam[i].typePlayer == LEFTPLAYER)
				{
					myTeam[i].GetBall();
				}
				else if (myTeam[i].typePlayer == RIGHTPLAYER)
				{
					myTeam[i].MoveTo(RIGHTPLAYER, myTeam[positionOfType[LEFTPLAYER]].GetPos());
				}
				else if (myTeam[i].typePlayer == DEFENCEPLAYER)
				{
					myTeam[i].MoveTo(RIGHTPLAYER, myTeam[positionOfType[LEFTPLAYER]].GetPos());
					myTeam[i].typePlayer = RIGHTPLAYER;
					positionOfType[RIGHTPLAYER] = i;
					positionOfType[DEFENCEPLAYER] = -1;
				}			
			}
			
		}
		else if (positionOfType[RIGHTPLAYER] > 0 && myTeam[iClosed].PassTo(myTeam[positionOfType[RIGHTPLAYER]].GetPos()))
		{
			for (i = 4; i > 0; i--)
			{
				if (i == iClosed)
				{
					continue;
				}
				if (myTeam[i].typePlayer == ATTACKPLAYERLEFT)
				{
					if (countAttack == 2)
					{
						myTeam[i].MoveTo(LEFTPLAYER, myTeam[positionOfType[RIGHTPLAYER]].GetPos());
						myTeam[i].typePlayer = LEFTPLAYER;
						positionOfType[LEFTPLAYER] = i;
						positionOfType[ATTACKPLAYERLEFT] = -1;
						countAttack--;
						countDef++;
					}
					else
					{
						myTeam[i].MoveTo(ATTACKPLAYERRIGHT, myTeam[positionOfType[RIGHTPLAYER]].GetPos());
						myTeam[i].typePlayer = ATTACKPLAYERRIGHT;
						positionOfType[ATTACKPLAYERRIGHT] = i;
						positionOfType[ATTACKPLAYERLEFT] = -1;
					}
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYERRIGHT)
				{
					myTeam[i].MoveTo(ATTACKPLAYERRIGHT, myTeam[positionOfType[RIGHTPLAYER]].GetPos());
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYER)
				{
					if (countAttack == 2
						&& positionOfType[ATTACKPLAYERRIGHT] >= 0)
					{
						myTeam[i].MoveTo(LEFTPLAYER, myTeam[positionOfType[RIGHTPLAYER]].GetPos());
						myTeam[i].typePlayer = LEFTPLAYER;
						positionOfType[LEFTPLAYER] = i;
						positionOfType[ATTACKPLAYER] = -1;
						countAttack--;
						countDef++;
					}
					else
					{
						myTeam[i].MoveTo(ATTACKPLAYERRIGHT, myTeam[positionOfType[RIGHTPLAYER]].GetPos());
						myTeam[i].typePlayer = ATTACKPLAYERRIGHT;
						positionOfType[ATTACKPLAYERRIGHT] = i;
						positionOfType[ATTACKPLAYER] = -1;
					}
				}
				else if (myTeam[i].typePlayer == LEFTPLAYER)
				{
					myTeam[i].MoveTo(LEFTPLAYER, myTeam[positionOfType[RIGHTPLAYER]].GetPos());
				}
				else if (myTeam[i].typePlayer == RIGHTPLAYER)
				{
					myTeam[i].GetBall();
				}
				else if (myTeam[i].typePlayer == DEFENCEPLAYER)
				{
					myTeam[i].MoveTo(LEFTPLAYER, myTeam[positionOfType[RIGHTPLAYER]].GetPos());
					myTeam[i].typePlayer = LEFTPLAYER;
					positionOfType[LEFTPLAYER] = i;
					positionOfType[DEFENCEPLAYER] = -1;
				}
				
			}
			
		}
		else
		{
			if (positionOfType[ATTACKPLAYERLEFT] > 0)
				myTeam[iClosed].SetTarget(myTeam[positionOfType[ATTACKPLAYERLEFT]].GetPos());
			else if (positionOfType[ATTACKPLAYERRIGHT] > 0)
				myTeam[iClosed].SetTarget(myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos());
			else if (positionOfType[ATTACKPLAYER] > 0)
				myTeam[iClosed].SetTarget(myTeam[positionOfType[ATTACKPLAYER]].GetPos());
			myTeam[iClosed].SetFoce(k_kick_foce);
			myTeam[iClosed].SetAction(KICK);
		}
	}
	else if (typeClosed == ATTACKPLAYERLEFT)
	{
		if (myTeam[iClosed].Shoot(true))
		{
		}
		else if (positionOfType[ATTACKPLAYER] > 0 && myTeam[iClosed].PassTo(myTeam[positionOfType[ATTACKPLAYER]].GetPos()))
		{
			for (i = 4; i > 0; i--)
			{
				if (i == iClosed)
				{
					continue;
				}
				if (myTeam[i].typePlayer == ATTACKPLAYER)
				{
					myTeam[i].GetBall();
				}
				else if (myTeam[i].typePlayer == CENTERPLAYER)
				{
					myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[ATTACKPLAYER]].GetPos());
				}
				else if (myTeam[i].typePlayer == LEFTPLAYER)
				{
					myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[ATTACKPLAYER]].GetPos());
					myTeam[i].typePlayer = DEFENCEPLAYER;
					positionOfType[DEFENCEPLAYER] = i;
					positionOfType[LEFTPLAYER] = -1;
				}
				else if (myTeam[i].typePlayer == RIGHTPLAYER)
				{
					myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[ATTACKPLAYER]].GetPos());
					myTeam[i].typePlayer = DEFENCEPLAYER;
					positionOfType[DEFENCEPLAYER] = i;
					positionOfType[RIGHTPLAYER] = -1;
				}
				else if (myTeam[i].typePlayer == DEFENCEPLAYER)
				{
					myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[ATTACKPLAYER]].GetPos());
				}				
			}
			
		}
		else if (positionOfType[ATTACKPLAYERRIGHT] > 0 && myTeam[iClosed].PassTo(myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos()))
		{
			for (i = 4;i > 0; i--)
			{
				if (myTeam[i].typePlayer == ATTACKPLAYERRIGHT)
				{
					myTeam[i].GetBall();
				}
				else if (myTeam[i].typePlayer == CENTERPLAYER)
				{
					myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos());
				}
				else if (myTeam[i].typePlayer == LEFTPLAYER)
				{
					myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos());
					myTeam[i].typePlayer = DEFENCEPLAYER;
					positionOfType[DEFENCEPLAYER] = i;
					positionOfType[LEFTPLAYER] = -1;
				}
				else if (myTeam[i].typePlayer == DEFENCEPLAYER)
				{
					myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos());
				}
				else if (myTeam[i].typePlayer == RIGHTPLAYER)
				{
					myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos());
					myTeam[i].typePlayer = DEFENCEPLAYER;
					positionOfType[DEFENCEPLAYER] = i;
					positionOfType[RIGHTPLAYER] = -1;
				}
			}
			
		}
		else if (positionOfType[CENTERPLAYER] > 0 && myTeam[iClosed].PassTo(myTeam[positionOfType[CENTERPLAYER]].GetPos()))
		{
			for (i = 4; i > 0; i--)
			{
				if (i == iClosed)
				{
					continue;
				}
				if (myTeam[i].typePlayer == ATTACKPLAYERRIGHT)
				{
					myTeam[i].MoveTo(ATTACKPLAYERRIGHT, myTeam[positionOfType[CENTERPLAYER]].GetPos());
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYER)
				{
					myTeam[i].MoveTo(ATTACKPLAYERRIGHT, myTeam[positionOfType[CENTERPLAYER]].GetPos());
					myTeam[i].typePlayer = ATTACKPLAYERRIGHT;
					positionOfType[ATTACKPLAYERRIGHT] = i;
					positionOfType[ATTACKPLAYER] = -1;
				}
				else if (myTeam[i].typePlayer == CENTERPLAYER)
				{
					myTeam[i].GetBall();
				}
				else if (myTeam[i].typePlayer == LEFTPLAYER)
				{
					myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[CENTERPLAYER]].GetPos());
					myTeam[i].typePlayer = DEFENCEPLAYER;
					if (positionOfType[DEFENCEPLAYER] < 0)
					{
						positionOfType[DEFENCEPLAYER] = i;
					}
					positionOfType[LEFTPLAYER] = -1;
				}
				else if (myTeam[i].typePlayer == RIGHTPLAYER)
				{
					if (countDef == 1)
					{
						myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[CENTERPLAYER]].GetPos());
						myTeam[i].typePlayer = DEFENCEPLAYER;
						positionOfType[DEFENCEPLAYER] = i;
						positionOfType[RIGHTPLAYER] = -1;
					}
					else
					{
						myTeam[i].MoveTo(ATTACKPLAYERRIGHT, myTeam[positionOfType[CENTERPLAYER]].GetPos());
						myTeam[i].typePlayer = ATTACKPLAYERRIGHT;
						positionOfType[ATTACKPLAYERRIGHT] = i;
						positionOfType[RIGHTPLAYER] = -1;
						countAttack++;
						countDef--;
					}
				}
				else if (myTeam[i].typePlayer == DEFENCEPLAYER)
				{
					if (countDef == 1
						|| positionOfType[RIGHTPLAYER] >= 0)
					{
						myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[CENTERPLAYER]].GetPos());
					}
					else
					{
						myTeam[i].MoveTo(ATTACKPLAYERRIGHT, myTeam[positionOfType[CENTERPLAYER]].GetPos());
						myTeam[i].typePlayer = ATTACKPLAYERRIGHT;
						positionOfType[ATTACKPLAYERRIGHT] = i;
						positionOfType[DEFENCEPLAYER] = -1;
						countAttack++;
						countDef--;
					}
				}
				
			}
			
		}
		else if (positionOfType[LEFTPLAYER] > 0 && myTeam[iClosed].PassTo(myTeam[positionOfType[LEFTPLAYER]].GetPos()))
		{
			for (i = 4; i >  0; i --)
			{
				if (i == iClosed)
				{
					continue;
				}
				if (myTeam[i].typePlayer == ATTACKPLAYERRIGHT)
				{
					myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[LEFTPLAYER]].GetPos());
					myTeam[i].typePlayer = CENTERPLAYER;
					if (positionOfType[CENTERPLAYER] < 0)
					{
						positionOfType[CENTERPLAYER] = i;
					}
					positionOfType[ATTACKPLAYERRIGHT] = -1;
					countAttack--;
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYER)
				{
					myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[LEFTPLAYER]].GetPos());
					myTeam[i].typePlayer = CENTERPLAYER;
					if (positionOfType[CENTERPLAYER] < 0)
					{
						positionOfType[CENTERPLAYER] = i;
					}
					positionOfType[ATTACKPLAYER] = -1;
					countAttack--;
				}
				else if (myTeam[i].typePlayer == CENTERPLAYER)
				{
					if (countDef == 1)
					{
						myTeam[i].MoveTo(RIGHTPLAYER, myTeam[positionOfType[LEFTPLAYER]].GetPos());
						myTeam[i].typePlayer = RIGHTPLAYER;
						positionOfType[RIGHTPLAYER] = i;
						positionOfType[CENTERPLAYER] = -1;
						countDef++;
					}
					else
					{
						myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[LEFTPLAYER]].GetPos());
					}
				}
				else if (myTeam[i].typePlayer == RIGHTPLAYER)
				{
					myTeam[i].MoveTo(RIGHTPLAYER, myTeam[positionOfType[LEFTPLAYER]].GetPos());
				}
				else if (myTeam[i].typePlayer == DEFENCEPLAYER)
				{
					myTeam[i].MoveTo(RIGHTPLAYER, myTeam[positionOfType[LEFTPLAYER]].GetPos());
					myTeam[i].typePlayer = RIGHTPLAYER;
					positionOfType[RIGHTPLAYER] = i;
					positionOfType[DEFENCEPLAYER] = -1;
				}

			}
			
		}
		else if (positionOfType[DEFENCEPLAYER] > 0 && myTeam[iClosed].PassTo(myTeam[positionOfType[DEFENCEPLAYER]].GetPos()))
		{
			for (i = 4; i > 0; i--)
			{
				if (i == iClosed)
				{
					continue;
				}
				if (myTeam[i].typePlayer == ATTACKPLAYERRIGHT)
				{
					myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[DEFENCEPLAYER]].GetPos());
					myTeam[i].typePlayer = CENTERPLAYER;
					if (positionOfType[CENTERPLAYER] < 0)
					{
						positionOfType[CENTERPLAYER] = i;
					}
					positionOfType[ATTACKPLAYERRIGHT] = -1;
					countAttack--;
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYER)
				{
					myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[DEFENCEPLAYER]].GetPos());
					myTeam[i].typePlayer = CENTERPLAYER;
					if (positionOfType[CENTERPLAYER] < 0)
					{
						positionOfType[CENTERPLAYER] = i;
					}
					positionOfType[ATTACKPLAYER] = -1;
					countAttack--;
				}
				else if (myTeam[i].typePlayer == CENTERPLAYER)
				{
					if (countDef == 2)
					{
						myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[DEFENCEPLAYER]].GetPos());
					}
					else
					{
						myTeam[i].MoveTo(RIGHTPLAYER, myTeam[positionOfType[DEFENCEPLAYER]].GetPos());
						myTeam[i].typePlayer = RIGHTPLAYER;
						positionOfType[CENTERPLAYER] = -1;
						countDef++;
					}
				}
				else if (myTeam[i].typePlayer == LEFTPLAYER)
				{
					myTeam[i].MoveTo(LEFTPLAYER, myTeam[positionOfType[DEFENCEPLAYER]].GetPos());
				}
				else if (myTeam[i].typePlayer == RIGHTPLAYER)
				{
					myTeam[i].MoveTo(RIGHTPLAYER, myTeam[positionOfType[DEFENCEPLAYER]].GetPos());
				}
				else if (myTeam[i].typePlayer == DEFENCEPLAYER)
				{
					myTeam[i].GetBall();
				}
				
			}
		}
		else
		{
			myTeam[iClosed].Shoot(false);
		}
	}
	else if (typeClosed == ATTACKPLAYERRIGHT)
	{
		if (myTeam[iClosed].Shoot(true)) //myTeam[iClosed].CanShoot()
		{
		}
		else if (positionOfType[ATTACKPLAYER] > 0 && myTeam[iClosed].PassTo(myTeam[positionOfType[ATTACKPLAYER]].GetPos()))
		{
			for (i = 4; i > 0; i--)
			{
				if (i == iClosed)
				{
					continue;
				}
				if (myTeam[i].typePlayer == ATTACKPLAYER)
				{
					myTeam[i].GetBall();
				}
				else if (myTeam[i].typePlayer == CENTERPLAYER)
				{
					myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[ATTACKPLAYER]].GetPos());
				}
				else if (myTeam[i].typePlayer == LEFTPLAYER)
				{
					myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[ATTACKPLAYER]].GetPos());
					myTeam[i].typePlayer = DEFENCEPLAYER;
					positionOfType[DEFENCEPLAYER] = i;
					positionOfType[LEFTPLAYER] = -1;
				}
				else if (myTeam[i].typePlayer == RIGHTPLAYER)
				{
					myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[ATTACKPLAYER]].GetPos());
					myTeam[i].typePlayer = DEFENCEPLAYER;
					positionOfType[DEFENCEPLAYER] = i;
					positionOfType[RIGHTPLAYER] = -1;
				}
				else if (myTeam[i].typePlayer == DEFENCEPLAYER)
				{
					myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[ATTACKPLAYER]].GetPos());
				}
				
			}
			
		}
		else if (positionOfType[ATTACKPLAYERLEFT] > 0 && myTeam[iClosed].PassTo(myTeam[positionOfType[ATTACKPLAYERLEFT]].GetPos()))
		{
			for (i = 4;i > 0; i--)
			{
				if (myTeam[i].typePlayer == ATTACKPLAYERLEFT)
				{
					myTeam[i].GetBall();
				}
				else if (myTeam[i].typePlayer == CENTERPLAYER)
				{
					myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[ATTACKPLAYERLEFT]].GetPos());
				}
				else if (myTeam[i].typePlayer == LEFTPLAYER)
				{
					myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[ATTACKPLAYERLEFT]].GetPos());
					myTeam[i].typePlayer = DEFENCEPLAYER;
					positionOfType[DEFENCEPLAYER] = i;
					positionOfType[LEFTPLAYER] = -1;
				}
				else if (myTeam[i].typePlayer == DEFENCEPLAYER)
				{
					myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[ATTACKPLAYERLEFT]].GetPos());
				}
				else if (myTeam[i].typePlayer == RIGHTPLAYER)
				{
					myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[ATTACKPLAYERLEFT]].GetPos());
					myTeam[i].typePlayer = DEFENCEPLAYER;
					positionOfType[DEFENCEPLAYER] = i;
					positionOfType[RIGHTPLAYER] = -1;
				}
			}
			
		}
		else if (positionOfType[CENTERPLAYER] > 0 && myTeam[iClosed].PassTo(myTeam[positionOfType[CENTERPLAYER]].GetPos()))
		{
			for (i = 4; i > 0; i--)
			{
				if (i == iClosed)
				{
					continue;
				}
				if (myTeam[i].typePlayer == ATTACKPLAYERLEFT)
				{
					myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[CENTERPLAYER]].GetPos());
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYER)
				{
					myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[CENTERPLAYER]].GetPos());
					myTeam[i].typePlayer = ATTACKPLAYERLEFT;
					positionOfType[ATTACKPLAYERLEFT] = i;
					positionOfType[ATTACKPLAYER] = -1;
				}
				else if (myTeam[i].typePlayer == CENTERPLAYER)
				{
					myTeam[i].GetBall();
				}
				else if (myTeam[i].typePlayer == LEFTPLAYER)
				{
					if (countDef == 1)
					{
						myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[CENTERPLAYER]].GetPos());
						myTeam[i].typePlayer = DEFENCEPLAYER;
						positionOfType[DEFENCEPLAYER] = i;
						positionOfType[LEFTPLAYER] = -1;
					}
					else
					{
						myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[CENTERPLAYER]].GetPos());
						myTeam[i].typePlayer = ATTACKPLAYERLEFT;
						positionOfType[ATTACKPLAYERLEFT] = i;
						positionOfType[LEFTPLAYER] = -1;
						countAttack++;
						countDef--;
					}
				}
				else if (myTeam[i].typePlayer == RIGHTPLAYER)
				{
					myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[CENTERPLAYER]].GetPos());
					myTeam[i].typePlayer = DEFENCEPLAYER;
					if (positionOfType[DEFENCEPLAYER] < 0)
					{
						positionOfType[DEFENCEPLAYER] = i;
					}
					positionOfType[RIGHTPLAYER] = -1;
				}
				else if (myTeam[i].typePlayer == DEFENCEPLAYER)
				{
					if (countDef == 1
						|| positionOfType[LEFTPLAYER] >= 0)
					{
						myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[CENTERPLAYER]].GetPos());
					}
					else
					{
						myTeam[i].MoveTo(ATTACKPLAYERLEFT, myTeam[positionOfType[CENTERPLAYER]].GetPos());
						myTeam[i].typePlayer = ATTACKPLAYERLEFT;
						positionOfType[ATTACKPLAYERLEFT] = i;
						positionOfType[DEFENCEPLAYER] = -1;
						countAttack++;
						countDef--;
					}
				}
				
			}
			
		}
		else if (positionOfType[RIGHTPLAYER] > 0 && myTeam[iClosed].PassTo(myTeam[positionOfType[RIGHTPLAYER]].GetPos()))
		{
			for (i = 4; i >  0; i --)
			{
				if (i == iClosed)
				{
					continue;
				}
				if (myTeam[i].typePlayer == ATTACKPLAYERLEFT)
				{
					myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[RIGHTPLAYER]].GetPos());
					myTeam[i].typePlayer = CENTERPLAYER;
					if (positionOfType[CENTERPLAYER] < 0)
					{
						positionOfType[CENTERPLAYER] = i;
					}
					positionOfType[ATTACKPLAYERLEFT] = -1;
					countAttack--;
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYER)
				{
					myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[RIGHTPLAYER]].GetPos());
					myTeam[i].typePlayer = CENTERPLAYER;
					if (positionOfType[CENTERPLAYER] < 0)
					{
						positionOfType[CENTERPLAYER] = i;
					}
					positionOfType[ATTACKPLAYER] = -1;
					countAttack--;
				}
				else if (myTeam[i].typePlayer == CENTERPLAYER)
				{
					if (countDef == 1)
					{
						myTeam[i].MoveTo(LEFTPLAYER, myTeam[positionOfType[RIGHTPLAYER]].GetPos());
						myTeam[i].typePlayer = LEFTPLAYER;
						positionOfType[LEFTPLAYER] = i;
						positionOfType[CENTERPLAYER] = -1;
						countDef++;
					}
					else
					{
						myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[RIGHTPLAYER]].GetPos());
					}
				}
				else if (myTeam[i].typePlayer == LEFTPLAYER)
				{
					myTeam[i].MoveTo(LEFTPLAYER, myTeam[positionOfType[RIGHTPLAYER]].GetPos());
				}
				else if (myTeam[i].typePlayer == DEFENCEPLAYER)
				{
					myTeam[i].MoveTo(LEFTPLAYER, myTeam[positionOfType[RIGHTPLAYER]].GetPos());
					myTeam[i].typePlayer = LEFTPLAYER;
					positionOfType[LEFTPLAYER] = i;
					positionOfType[DEFENCEPLAYER] = -1;
				}
			}
			
		}
		else if (positionOfType[DEFENCEPLAYER] > 0 && myTeam[iClosed].PassTo(myTeam[positionOfType[DEFENCEPLAYER]].GetPos()))
		{
			for (i = 4; i > 0; i--)
			{
				if (i == iClosed)
				{
					continue;
				}
				if (myTeam[i].typePlayer == ATTACKPLAYERLEFT)
				{
					myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[DEFENCEPLAYER]].GetPos());
					myTeam[i].typePlayer = CENTERPLAYER;
					if (positionOfType[CENTERPLAYER] < 0)
					{
						positionOfType[CENTERPLAYER] = i;
					}
					positionOfType[ATTACKPLAYERLEFT] = -1;
					countAttack--;
				}
				else if (myTeam[i].typePlayer == ATTACKPLAYER)
				{
					myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[DEFENCEPLAYER]].GetPos());
					myTeam[i].typePlayer = CENTERPLAYER;
					if (positionOfType[CENTERPLAYER] < 0)
					{
						positionOfType[CENTERPLAYER] = i;
					}
					positionOfType[ATTACKPLAYER] = -1;
					countAttack--;
				}
				else if (myTeam[i].typePlayer == CENTERPLAYER)
				{
					if (countDef == 2)
					{
						myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[DEFENCEPLAYER]].GetPos());
					}
					else
					{
						myTeam[i].MoveTo(LEFTPLAYER, myTeam[positionOfType[DEFENCEPLAYER]].GetPos());
						myTeam[i].typePlayer = LEFTPLAYER;
						positionOfType[CENTERPLAYER] = -1;
						countDef++;
					}
				}
				else if (myTeam[i].typePlayer == LEFTPLAYER)
				{
					myTeam[i].MoveTo(LEFTPLAYER, myTeam[positionOfType[DEFENCEPLAYER]].GetPos());
				}
				else if (myTeam[i].typePlayer == RIGHTPLAYER)
				{
					myTeam[i].MoveTo(RIGHTPLAYER, myTeam[positionOfType[DEFENCEPLAYER]].GetPos());
				}
				else if (myTeam[i].typePlayer == DEFENCEPLAYER)
				{
					myTeam[i].GetBall();
				}				
			}
			
		}
		else if (positionOfType[ATTACKPLAYERRIGHT] > 0 && myTeam[iClosed].PassTo(myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos()))
		{
			for (i = 4; i > 0; i--)
			{
				if (i == iClosed)
				{
					continue;
				}
				if (myTeam[i].typePlayer == ATTACKPLAYERRIGHT)
				{
					myTeam[i].GetBall();
				}
				else if (myTeam[i].typePlayer == CENTERPLAYER)
				{
					myTeam[i].MoveTo(CENTERPLAYER, myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos());
				}
				else if (myTeam[i].typePlayer == LEFTPLAYER)
				{
					myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos());
					myTeam[i].typePlayer = DEFENCEPLAYER;
					positionOfType[DEFENCEPLAYER] = i;
					positionOfType[LEFTPLAYER] = -1;
				}
				else if (myTeam[i].typePlayer == RIGHTPLAYER)
				{
					myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos());
					myTeam[i].typePlayer = DEFENCEPLAYER;
					positionOfType[DEFENCEPLAYER] = i;
					positionOfType[RIGHTPLAYER] = -1;
				}
				else if (myTeam[i].typePlayer == DEFENCEPLAYER)
				{
					myTeam[i].MoveTo(DEFENCEPLAYER, myTeam[positionOfType[ATTACKPLAYERRIGHT]].GetPos());
				}				
			}
			
		}
		else
		{
			myTeam[iClosed].Shoot(false);
		}
	}
	for (i = 0; i < 8; i++)
	{
		positionOfType[i] = PositionOfType((PLAYERTYPE)i);
	}

	countDef = 0;
	countAttack = 0;
	countCenter = 0;
	if (positionOfType[LEFTPLAYER] > 0)
	{
		countDef++;
	}
	if (positionOfType[RIGHTPLAYER] > 0)
	{
		countDef++;
	}
	if (positionOfType[DEFENCEPLAYER] > 0)
	{
		countDef++;
	}
	if (positionOfType[ATTACKPLAYERLEFT] > 0)
	{
		countAttack++;
	}
	if (positionOfType[ATTACKPLAYERRIGHT] > 0)
	{
		countAttack++;
	}
	if (positionOfType[ATTACKPLAYER] > 0)
	{
		countAttack++;
	}
	if (positionOfType[CENTERPLAYER] > 0)
	{
		countCenter++;
	}
	if (countAttack + countDef == 3 && ( countAttack == 1 || countDef == 1) && countCenter == 1)
	{
	}
	else
	{
		std::cout<<"ATTACK END----"<<countAttack<<"--"<<countCenter<<"--"<<countDef<<std::endl;
	}
}
void OwerTeam::Defence()
{
	PLAYERTYPE positionOfBall = AITeamState::GetInstance()->GetAreaOfBall(); // = AITeamState::GetInstance()->....
	int positionOfType[8];
	int countDef = 0;
	int countAttack = 0;
	int countCenter = 0;
	int iClosed = AITeamState::GetInstance()->closestPeople;
	PLAYERTYPE typeClosed = myTeam[iClosed].typePlayer;
	int i = 0;
	for (i = 0; i < 8; i++)
	{
		positionOfType[i] = PositionOfType((PLAYERTYPE)i);
	}

	if (positionOfType[LEFTPLAYER] > 0)
	{
		countDef++;
	}
	if (positionOfType[RIGHTPLAYER] > 0)
	{
		countDef++;
	}
	if (positionOfType[DEFENCEPLAYER] > 0)
	{
		countDef++;
	}
	if (positionOfType[ATTACKPLAYERLEFT] > 0)
	{
		countAttack++;
	}
	if (positionOfType[ATTACKPLAYERRIGHT] > 0)
	{
		countAttack++;
	}
	if (positionOfType[ATTACKPLAYER] > 0)
	{
		countAttack++;
	}
	if (positionOfType[CENTERPLAYER] > 0)
	{
		countCenter++;
	}

	if (countAttack + countDef == 3 && ( countAttack == 1 || countDef == 1) && countCenter == 1 )
	{
	}
	else
	{
		std::cout<<"Defence START count Attack "<<countAttack<<" count Def "<<countDef<<std::endl;
	}

	if (positionOfBall == ATTACKPLAYERLEFT)
	{
		for (i = 4; i > 0; i--)
		{
			if (myTeam[i].typePlayer == ATTACKPLAYERLEFT)
			{
				myTeam[i].GetBall();
			}
			else if (myTeam[i].typePlayer == ATTACKPLAYER)
			{
				if (positionOfType[ATTACKPLAYERLEFT] > 0)
				{
					myTeam[i].StandAt(ATTACKPLAYER);
				}
				else
				{
					myTeam[i].GetBall();
					myTeam[i].typePlayer = ATTACKPLAYERLEFT;
					if (positionOfType[ATTACKPLAYERLEFT] < 0)
						positionOfType[ATTACKPLAYERLEFT] = i;
					positionOfType[ATTACKPLAYER] = -1;
				}
			}
			else if (myTeam[i].typePlayer == ATTACKPLAYERRIGHT)
			{
				if (countAttack > 1)
				{
					myTeam[i].StandAt(ATTACKPLAYER);
					myTeam[i].typePlayer = ATTACKPLAYER;
					if (positionOfType[ATTACKPLAYER] < 0)
						positionOfType[ATTACKPLAYER] = i;
					positionOfType[ATTACKPLAYERRIGHT] = -1;
				}
				else
				{
					myTeam[i].GetBall();
					myTeam[i].typePlayer = ATTACKPLAYERLEFT;
					if (positionOfType[ATTACKPLAYERLEFT] < 0)
						positionOfType[ATTACKPLAYERLEFT] = i;
					positionOfType[ATTACKPLAYERRIGHT] = -1;
				}

			}
			else if (myTeam[i].typePlayer == CENTERPLAYER)
			{
				if (countAttack == 1)
				{
					if (positionOfType[ATTACKPLAYERLEFT] < 0)
					{
						myTeam[i].GetBall();
						myTeam[i].typePlayer = ATTACKPLAYERLEFT;
						positionOfType[ATTACKPLAYERLEFT] = i;
					}
					else
					{
						myTeam[i].StandAt(ATTACKPLAYER);
						myTeam[i].typePlayer = ATTACKPLAYER;
						positionOfType[ATTACKPLAYER] = i;
					}
					
					positionOfType[CENTERPLAYER] = -1;
					countAttack++;
					countCenter--;
				}
				else
				{
					myTeam[i].StandAt(CENTERPLAYER);
				}

			}
			else if (myTeam[i].typePlayer == LEFTPLAYER)
			{
				//Dung vi tri ( Khu vuc LEFT_PLAYER )
				myTeam[i].StandAt(LEFTPLAYER);
			}
			else if (myTeam[i].typePlayer == RIGHTPLAYER)
			{
				if (countDef == 1)
				{
					//Dung vi tri( Khu vuc LEFT_PLAYER )
					myTeam[i].StandAt(LEFTPLAYER);
					myTeam[i].typePlayer = LEFTPLAYER;
					if (positionOfType[LEFTPLAYER] < 0)
						positionOfType[LEFTPLAYER] = i;
					positionOfType[RIGHTPLAYER] = -1;
				}
				else
				{
					//Dung vi tri( Khu vuc CENTER )
					myTeam[i].StandAt(CENTERPLAYER);
					myTeam[i].typePlayer = CENTERPLAYER;
					if (positionOfType[CENTERPLAYER] < 0)
						positionOfType[CENTERPLAYER] = i;
					positionOfType[RIGHTPLAYER] = -1;
					countDef--;
					countCenter++;
				}

			}
			else if (myTeam[i].typePlayer == DEFENCEPLAYER)
			{
				if (countDef == 1 || positionOfType[LEFTPLAYER] < 0)
				{
					//Dung vi tri( Khu vuc LEFT_PLAYER )
					myTeam[i].StandAt(LEFTPLAYER);
					myTeam[i].typePlayer = LEFTPLAYER;
					if (positionOfType[LEFTPLAYER] < 0)
						positionOfType[LEFTPLAYER] = i;
					positionOfType[DEFENCEPLAYER] = -1;
				}
				else
				{
					//Dung vi tri( Khu vuc CENTER )
					myTeam[i].StandAt(CENTERPLAYER);
					myTeam[i].typePlayer = CENTERPLAYER;
					if (positionOfType[CENTERPLAYER] < 0)
						positionOfType[CENTERPLAYER] = i;
					positionOfType[DEFENCEPLAYER] = -1;
					countDef--;
					countCenter++;
				}

			}
		}
		
	}
	else if (positionOfBall == ATTACKPLAYER)
	{
		for (i = 4; i > 0; i--)
		{
			if (myTeam[i].typePlayer == ATTACKPLAYERLEFT)
			{
				//Dung vi tri (Khu vuc ATTACKPLAYERLEFT, verto2d vi tri nguoi theo bong, ..vi tri bong )
				myTeam[i].StandAt(ATTACKPLAYERLEFT);
			}
			else if (myTeam[i].typePlayer == ATTACKPLAYER)
			{
				if (positionOfType[ATTACKPLAYERLEFT] > 0)
				{
					//Dung vi tri(Khu vuc ATTACKPLAYERRIGHT
					myTeam[i].StandAt(ATTACKPLAYERRIGHT);
					myTeam[i].typePlayer = ATTACKPLAYERRIGHT;
					if (positionOfType[ATTACKPLAYERRIGHT] < 0)
						positionOfType[ATTACKPLAYERRIGHT] = i;
					positionOfType[ATTACKPLAYER] = -1;
				}
				else
				{
					//Dung vi tri(Khu vuc ATTACKPLAYERLEFT
					myTeam[i].StandAt(ATTACKPLAYERLEFT);
					myTeam[i].typePlayer = ATTACKPLAYERLEFT;
					if (positionOfType[ATTACKPLAYERLEFT] < 0)
						positionOfType[ATTACKPLAYERLEFT] = i;
					positionOfType[ATTACKPLAYER] = -1;
				}
			}
			else if (myTeam[i].typePlayer == ATTACKPLAYERRIGHT)
			{
				//Dung vi tri ( Khu vuc ATTACK_PLAYERRIGHT
				myTeam[i].StandAt(ATTACKPLAYERRIGHT);
			}
			else if (myTeam[i].typePlayer == CENTERPLAYER)
			{
				//Theo bong, van giu trang thai CENTERPLAYER
				myTeam[i].GetBall();
			}
			else if (myTeam[i].typePlayer == LEFTPLAYER)
			{
				if (countDef == 1
					|| positionOfType[ATTACKPLAYERLEFT] > 0)
				{
					//Dung vi tri ( Khu vuc DEFENCE_PLAYER )
					myTeam[i].StandAt(DEFENCEPLAYER);
					myTeam[i].typePlayer = DEFENCEPLAYER;
					if (positionOfType[DEFENCEPLAYER] < 0)
						positionOfType[DEFENCEPLAYER] = i;
					positionOfType[LEFTPLAYER] = -1;
				}
				else
				{
					//Dung vi tri ( Khu vuc ATTACK_PLAYER_LEFT
					myTeam[i].StandAt(ATTACKPLAYERLEFT);
					myTeam[i].typePlayer = ATTACKPLAYERLEFT;
					if (positionOfType[ATTACKPLAYERLEFT] < 0)
						positionOfType[ATTACKPLAYERLEFT] = i;
					positionOfType[LEFTPLAYER] = -1;
					countAttack++;
					countDef--;
				}
				
			}
			else if (myTeam[i].typePlayer == RIGHTPLAYER)
			{
				if(countDef == 1
					|| positionOfType[ATTACKPLAYERRIGHT] > 0)
				{
					//Dung vi tri ( Khu vuc DEFENCE_PLAYER )
					myTeam[i].StandAt(DEFENCEPLAYER);
					myTeam[i].typePlayer = DEFENCEPLAYER;
					if (positionOfType[DEFENCEPLAYER] < 0)
						positionOfType[DEFENCEPLAYER] = i;
					positionOfType[RIGHTPLAYER] = -1;
				}
				else
				{
					//Dung vi tri ( Khu vuc ATTACK_PLAYER_RIGHT
					myTeam[i].StandAt(ATTACKPLAYERRIGHT);
					myTeam[i].typePlayer = ATTACKPLAYERRIGHT;
					if (positionOfType[ATTACKPLAYERRIGHT] < 0)
						positionOfType[ATTACKPLAYERRIGHT] = i;
					positionOfType[RIGHTPLAYER] = -1;
					countAttack++;
					countDef--;
				}

			}
			else if (myTeam[i].typePlayer == DEFENCEPLAYER)
			{
				if (countDef == 1)
				{
					//Dung vi tri( Khu vuc DEFENCE PLAYER )
					myTeam[i].StandAt(DEFENCEPLAYER);
				}
				else
				{
					if (positionOfType[ATTACKPLAYERLEFT] < 0)
					{
						//Dung vi tri ( Khu vuc ATTACKPLAYERLEFT
						myTeam[i].StandAt(ATTACKPLAYERLEFT);
						myTeam[i].typePlayer = ATTACKPLAYERLEFT;
						if (positionOfType[ATTACKPLAYERLEFT] < 0)
							positionOfType[ATTACKPLAYERLEFT] = i;
						positionOfType[DEFENCEPLAYER] = -1;
						countAttack++;
						countDef--;
					}
					else
					{
						//Dung vi tri ( Khu vuc ATTACKPLAYERRIGHT
						myTeam[i].StandAt(ATTACKPLAYERRIGHT);
						myTeam[i].typePlayer = ATTACKPLAYERRIGHT;
						if (positionOfType[ATTACKPLAYERRIGHT] < 0)
							positionOfType[ATTACKPLAYERRIGHT] = i;
						positionOfType[DEFENCEPLAYER] = -1;
						countAttack++;
						countDef--;
					}
				}
			}
		}
		
	}
	else if (positionOfBall == ATTACKPLAYERRIGHT)
	{
		for (i = 4; i > 0; i--)
		{
			if (myTeam[i].typePlayer == ATTACKPLAYERLEFT)
			{
				if (countAttack > 1)
				{
					//Dung vi tri ( Khu vuc ATTACK_PLAYER)
					myTeam[i].StandAt(ATTACKPLAYER);
					myTeam[i].typePlayer = ATTACKPLAYER;
					if (positionOfType[ATTACKPLAYER] < 0)
						positionOfType[ATTACKPLAYER] = i;
					positionOfType[ATTACKPLAYERLEFT] = -1;
				}
				else
				{
					// theo bong
					myTeam[i].GetBall();
					myTeam[i].typePlayer = ATTACKPLAYERRIGHT;
					if (positionOfType[ATTACKPLAYERRIGHT] < 0)
						positionOfType[ATTACKPLAYERRIGHT] = i;
					positionOfType[ATTACKPLAYERLEFT] = -1;
				}
			}
			else if (myTeam[i].typePlayer == ATTACKPLAYER)
			{
				if (positionOfType[ATTACKPLAYERRIGHT] > 0)
				{
					//Dung vi tri (Khu vuc ATTACKPLAYER, verto2d vi tri nguoi theo bong, ..vi tri bong )
					myTeam[i].StandAt(ATTACKPLAYER);
				}
				else
				{
					//Theo bong
					myTeam[i].GetBall();
					myTeam[i].typePlayer = ATTACKPLAYERRIGHT;
					if (positionOfType[ATTACKPLAYERRIGHT] < 0)
						positionOfType[ATTACKPLAYERRIGHT] = i;
					positionOfType[ATTACKPLAYER] = -1;
				}
			}
			else if (myTeam[i].typePlayer == ATTACKPLAYERRIGHT)
			{
				myTeam[i].GetBall();
			}
			else if (myTeam[i].typePlayer == CENTERPLAYER)
			{
				if (countAttack == 1)
				{
					if (positionOfType[ATTACKPLAYERRIGHT] < 0)
					{
						myTeam[i].GetBall();
						myTeam[i].typePlayer = ATTACKPLAYERRIGHT;
						positionOfType[ATTACKPLAYERRIGHT] = i;
					}
					else
					{
						//Dung vi tri ( Khu vuc ATTACK_PLAYER)
						myTeam[i].StandAt(ATTACKPLAYER);
						myTeam[i].typePlayer = ATTACKPLAYER;
						if (positionOfType[ATTACKPLAYER] < 0)
							positionOfType[ATTACKPLAYER] = i;
					}
					positionOfType[CENTERPLAYER] = -1;
					countCenter--;
					countAttack++;
				}
				else
				{
					//Dung vi tri ( Khu vuc CENTER_PLAYER)
					myTeam[i].StandAt(CENTERPLAYER);
				}
			}
			else if (myTeam[i].typePlayer == LEFTPLAYER)
			{
				if (countDef == 1)
				{
					//Dung vi tri( Khu vuc RIGHT_PLAYER )
					myTeam[i].StandAt(RIGHTPLAYER);
					myTeam[i].typePlayer = RIGHTPLAYER;
					if (positionOfType[RIGHTPLAYER] < 0)
						positionOfType[RIGHTPLAYER] = i;
					positionOfType[LEFTPLAYER] = -1;
				}
				else
				{
					//Dung vi tri( Khu vuc CENTER )
					myTeam[i].StandAt(CENTERPLAYER);
					myTeam[i].typePlayer = CENTERPLAYER;
					if (positionOfType[CENTERPLAYER] < 0)
						positionOfType[CENTERPLAYER] = i;
					positionOfType[LEFTPLAYER] = -1;
					countDef--;
					countCenter++;
				}
			}
			else if (myTeam[i].typePlayer == RIGHTPLAYER)
			{
				//Dung vi tri ( Khu vuc RIGHT_PLAYER )
				myTeam[i].StandAt(RIGHTPLAYER);
			}
			else if (myTeam[i].typePlayer == DEFENCEPLAYER)
			{
				if (positionOfType[RIGHTPLAYER] < 0)
				{
					//Dung vi tri( Khu vuc RIGHT_PLAYER )
					myTeam[i].StandAt(RIGHTPLAYER);
					myTeam[i].typePlayer = RIGHTPLAYER;
					positionOfType[RIGHTPLAYER] = i;
					positionOfType[DEFENCEPLAYER] = -1;
				}
				else
				{
					//Dung vi tri( Khu vuc CENTER )
					myTeam[i].StandAt(CENTERPLAYER);
					myTeam[i].typePlayer = CENTERPLAYER;
					if (positionOfType[CENTERPLAYER] < 0)
						positionOfType[CENTERPLAYER] = i;
					positionOfType[DEFENCEPLAYER] = -1;
					countDef--;
					countCenter++;
				}
			}
		}
		
	}
	else if (positionOfBall == CENTERPLAYER)
	{
		for (i = 4; i > 0; i--)
		{
			if (myTeam[i].typePlayer == ATTACKPLAYERLEFT)
			{
				if (countAttack == 1 || positionOfType[LEFTPLAYER] >= 0)
				{
					//Dung vi tri( Khu vuc ATTACKPLAYER ) =>type ATTACKPLAYER
					myTeam[i].StandAt(ATTACKPLAYER);
					myTeam[i].typePlayer = ATTACKPLAYER;
					if (positionOfType[ATTACKPLAYER] < 0)
						positionOfType[ATTACKPLAYER] = i;
					positionOfType[ATTACKPLAYERLEFT] = -1;
				}
				else
				{
					//Dung vi tri( Khu vuc LEFTCENTER ) =>type LEFTCENTER
					myTeam[i].StandAt(LEFTPLAYER);
					myTeam[i].typePlayer = LEFTPLAYER;
					if (positionOfType[LEFTPLAYER] < 0)
						positionOfType[LEFTPLAYER] = i;
					positionOfType[ATTACKPLAYERLEFT] = -1;
					countAttack--;
					countDef++;
				}
			}
			else if (myTeam[i].typePlayer == ATTACKPLAYER)
			{
				if (countAttack == 1)
				{
					//Dung vi tri( Khu vuc ATTACKPLAYER ) =>type ATTACKPLAYER
					myTeam[i].StandAt(ATTACKPLAYER);
				}
				else if (positionOfType[LEFTPLAYER] < 0 && positionOfType[ATTACKPLAYERLEFT] < 0)
				{
					//Dung vi tri( Khu vuc LEFTCENTER ) =>type LEFTCENTER
					myTeam[i].StandAt(LEFTPLAYER);
					myTeam[i].typePlayer = LEFTPLAYER;
					if (positionOfType[LEFTPLAYER] < 0)
						positionOfType[LEFTPLAYER] = i;
					positionOfType[ATTACKPLAYER] = -1;
					countAttack--;
					countDef++;
				}
				else if (positionOfType[RIGHTPLAYER] < 0 && positionOfType[ATTACKPLAYERRIGHT] < 0)
				{
					//Dung vi tri( Khu vuc RIGHTPLAYER ) =>type RIGHTPLAYER
					myTeam[i].StandAt(RIGHTPLAYER);
					myTeam[i].typePlayer = RIGHTPLAYER;
					if (positionOfType[RIGHTPLAYER] < 0)
						positionOfType[RIGHTPLAYER] = i;
					positionOfType[ATTACKPLAYER] = -1;
					countAttack--;
					countDef++;
				}
				else
				{
					myTeam[i].StandAt(ATTACKPLAYER);
				}

			}
			else if (myTeam[i].typePlayer == ATTACKPLAYERRIGHT)
			{
				if (countAttack == 1 || positionOfType[RIGHTPLAYER] >= 0)
				{
					//Dung vi tri( Khu vuc ATTACKPLAYER ) =>type ATTACKPLAYER
					myTeam[i].StandAt(ATTACKPLAYER);
					myTeam[i].typePlayer = ATTACKPLAYER;
					if (positionOfType[ATTACKPLAYER] < 0)
						positionOfType[ATTACKPLAYER] = i;
					positionOfType[ATTACKPLAYERRIGHT] = -1;
				}
				else
				{
					//Dung vi tri( Khu vuc RIGHTPLAYER ) =>type RIGHTPLAYER
					myTeam[i].StandAt(RIGHTPLAYER);
					myTeam[i].typePlayer = RIGHTPLAYER;
					if (positionOfType[RIGHTPLAYER] < 0)
						positionOfType[RIGHTPLAYER] = i;
					positionOfType[ATTACKPLAYERRIGHT] = -1;
					countAttack--;
					countDef++;
				}
			}
			else if (myTeam[i].typePlayer == CENTERPLAYER)
			{
				//Duoi theo bong
				myTeam[i].GetBall();
			}
			else if (myTeam[i].typePlayer == LEFTPLAYER)
			{
				//Dung vi tri( Khu vuc LEFTPLAYER )
				myTeam[i].StandAt(LEFTPLAYER);
			}
			else if (myTeam[i].typePlayer == RIGHTPLAYER)
			{
				//Dung vi tri( Khu vuc RIGHTPLAYER )
				myTeam[i].StandAt(RIGHTPLAYER);
			}
			else if (myTeam[i].typePlayer == DEFENCEPLAYER)
			{
				if (positionOfType[LEFTPLAYER] < 0)
				{
					//Dung vi tri( Khu vuc LEFTPLAYER ) => Type = LEFTPLAYER
					myTeam[i].StandAt(LEFTPLAYER);
					myTeam[i].typePlayer = LEFTPLAYER;
					if (positionOfType[LEFTPLAYER] < 0)
						positionOfType[LEFTPLAYER] = i;
					positionOfType[DEFENCEPLAYER] = -1;
				}
				else if(positionOfType[RIGHTPLAYER] < 0)
				{
					//Dung vi tri( Khu vuc RIGHTPLAYER ) => Type = RIGHTPLAYER
					myTeam[i].StandAt(RIGHTPLAYER);
					myTeam[i].typePlayer = RIGHTPLAYER;
					if (positionOfType[RIGHTPLAYER] < 0)
						positionOfType[RIGHTPLAYER] = i;
					positionOfType[DEFENCEPLAYER] = -1;
				}
			}
		}
		
	}
	else if (positionOfBall == LEFTPLAYER)
	{
		for (i = 4; i > 0; i--)
		{
			if (myTeam[i].typePlayer == ATTACKPLAYERLEFT)
			{
				//Dung vi tri( Khu vuc ATTACKPLAYERLEFT )
				myTeam[i].StandAt(ATTACKPLAYERLEFT);
			}
			else if (myTeam[i].typePlayer == ATTACKPLAYER)
			{
				if (positionOfType[ATTACKPLAYERLEFT] < 0)
				{
					//Dung vi tri( Khu vuc ATTACKPLAYER)
					myTeam[i].StandAt(ATTACKPLAYERLEFT);
					myTeam[i].typePlayer = ATTACKPLAYERLEFT;
					positionOfType[ATTACKPLAYERLEFT] = i;
					positionOfType[ATTACKPLAYER] = -1;
				}
				else
				{
					//Dung vi tri( Khu vuc CENTERPLAYER)
					myTeam[i].StandAt(CENTERPLAYER);
					myTeam[i].typePlayer = CENTERPLAYER;
					if (positionOfType[CENTERPLAYER] < 0)
						positionOfType[CENTERPLAYER] = i;
					positionOfType[ATTACKPLAYER] = -1;
					countAttack--;
					countCenter++;
				}
			}
			else if (myTeam[i].typePlayer == ATTACKPLAYERRIGHT)
			{
				myTeam[i].StandAt(CENTERPLAYER);
				myTeam[i].typePlayer = CENTERPLAYER;
				if (positionOfType[CENTERPLAYER] < 0)
					positionOfType[CENTERPLAYER] = i;
				positionOfType[ATTACKPLAYERRIGHT] = -1;
				countAttack--;
				countCenter++;
				//Dung vi tri ( Khu vuc CENTERPLAYER)
			}
			else if (myTeam[i].typePlayer == CENTERPLAYER)
			{
				if (countDef == 2)
				{
					if (positionOfType[ATTACKPLAYERLEFT] >= 0 || positionOfType[ATTACKPLAYER] >= 0)
					{
						//Dung vi tri ( Khu vuc CENTERPLAYER)
						myTeam[i].StandAt(CENTERPLAYER);
					}
					else
					{
						//Dung vi tri ( Khu vuc ATTACKPLAYERLEFT)
						myTeam[i].StandAt(ATTACKPLAYERLEFT);
						myTeam[i].typePlayer = ATTACKPLAYERLEFT;
						if (positionOfType[ATTACKPLAYERLEFT] < 0)
							positionOfType[ATTACKPLAYERLEFT] = i;
						positionOfType[CENTERPLAYER] = -1;
						countAttack++;
						countCenter--;
					}
				}
				else
				{
					if (positionOfType[LEFTPLAYER] >= 0)
					{
						//Dung vi tri ( Khu vuc DEFENCEPLAYER)
						myTeam[i].StandAt(DEFENCEPLAYER);
						myTeam[i].typePlayer = DEFENCEPLAYER;
						if (positionOfType[DEFENCEPLAYER] < 0)
							positionOfType[DEFENCEPLAYER] = i;
						positionOfType[CENTERPLAYER] = -1;
						countDef++;
						countCenter--;
					}
					else
					{
						//Duoi theo bong => LEFTPLAYER
						myTeam[i].GetBall();
						myTeam[i].typePlayer = LEFTPLAYER;
						if (positionOfType[LEFTPLAYER] < 0)
							positionOfType[LEFTPLAYER] = i;
						positionOfType[CENTERPLAYER] = -1;
						countDef++;
						countCenter--;
					}
				}
			}
			else if (myTeam[i].typePlayer == LEFTPLAYER)
			{
				//Duoi theo bong => LEFTPLAYER
				myTeam[i].GetBall();
			}
			else if (myTeam[i].typePlayer == DEFENCEPLAYER)
			{
				if (countDef == 2 && positionOfType[LEFTPLAYER] < 0)
				{
					//Duoi theo bong => LEFTPLAYER
					myTeam[i].GetBall();
					myTeam[i].typePlayer = LEFTPLAYER;
					positionOfType[LEFTPLAYER] = i;
					positionOfType[DEFENCEPLAYER] = -1;
				}
				else
				{
					//Dung vi tri DEFENCEPLAYER
					myTeam[i].StandAt(DEFENCEPLAYER);
				}
			}
			else if (myTeam[i].typePlayer == RIGHTPLAYER)
			{
				//Dung vi tri DEFENCEPLAYER
				myTeam[i].StandAt(DEFENCEPLAYER);
				myTeam[i].typePlayer = DEFENCEPLAYER;
				if (positionOfType[DEFENCEPLAYER] < 0)
					positionOfType[DEFENCEPLAYER] = i;
				positionOfType[RIGHTPLAYER] = -1;
			}
		}
		
	}
	else if (positionOfBall == DEFENCEPLAYER)
	{
		for (i = 4; i > 0; i--)
		{
			if (myTeam[i].typePlayer == ATTACKPLAYERLEFT)
			{
				//Dung vi tri ATTACKPLAYER
				if (countAttack == 1)
				{
					myTeam[i].StandAt(ATTACKPLAYER);
					myTeam[i].typePlayer = ATTACKPLAYER;
					if (positionOfType[ATTACKPLAYER] < 0)
						positionOfType[ATTACKPLAYER] = i;
					positionOfType[ATTACKPLAYERLEFT] = -1;
				}
				else
				{
					if (positionOfType[LEFTPLAYER] < 0)
					{
						//Dung vi tri LEFTPLAYER
						myTeam[i].StandAt(LEFTPLAYER);
						myTeam[i].typePlayer = LEFTPLAYER;
						if (positionOfType[LEFTPLAYER] < 0)
							positionOfType[LEFTPLAYER] = i;
						positionOfType[ATTACKPLAYERLEFT] = -1;
						countAttack--;
						countDef++;
					}
					else
					{
						//Dung vi tri RIGHTPLAYER
						myTeam[i].StandAt(RIGHTPLAYER);
						myTeam[i].typePlayer = RIGHTPLAYER;
						if (positionOfType[RIGHTPLAYER] < 0)
							positionOfType[RIGHTPLAYER] = i;
						positionOfType[ATTACKPLAYERLEFT] = -1;
						countAttack--;
						countDef++;
					}
				}
			}
			else if (myTeam[i].typePlayer == ATTACKPLAYER)
			{
				//Dung vi tri ATTACKPLAYER
				myTeam[i].StandAt(ATTACKPLAYER);
			}
			else if (myTeam[i].typePlayer == ATTACKPLAYERRIGHT)
			{
				//Dung vi tri ATTACKPLAYER
				if (countAttack == 1)
				{
					myTeam[i].StandAt(ATTACKPLAYER);
					myTeam[i].typePlayer = ATTACKPLAYER;
					if (positionOfType[ATTACKPLAYER] < 0)
						positionOfType[ATTACKPLAYER] = i;
					positionOfType[ATTACKPLAYERRIGHT] = -1;
				}
				else
				{
					if (positionOfType[LEFTPLAYER] < 0)
					{
						//Dung vi tri LEFTPLAYER
						myTeam[i].StandAt(LEFTPLAYER);
						myTeam[i].typePlayer = LEFTPLAYER;
						if (positionOfType[LEFTPLAYER] < 0)
							positionOfType[LEFTPLAYER] = i;
						positionOfType[ATTACKPLAYERRIGHT] = -1;
						countAttack--;
						countDef++;
					}
					else
					{
						//Dung vi tri RIGHTPLAYER
						myTeam[i].StandAt(RIGHTPLAYER);
						myTeam[i].typePlayer = RIGHTPLAYER;
						if (positionOfType[RIGHTPLAYER] < 0)
							positionOfType[RIGHTPLAYER] = i;
						positionOfType[ATTACKPLAYERRIGHT] = -1;
						countAttack--;
						countDef++;
					}
				}
			}
			else if (myTeam[i].typePlayer == CENTERPLAYER)
			{
				if (positionOfType[DEFENCEPLAYER] > 0 
					|| countCenter == 2)
				{
					if (positionOfType[LEFTPLAYER] < 0)
					{
						myTeam[i].StandAt(LEFTPLAYER);
						myTeam[i].typePlayer = LEFTPLAYER;
						positionOfType[LEFTPLAYER] = i;
						positionOfType[CENTERPLAYER] = -1;
						countDef++;
						countCenter--;
					}
					else if (positionOfType[RIGHTPLAYER] < 0)
					{
						myTeam[i].StandAt(RIGHTPLAYER);
						myTeam[i].typePlayer = RIGHTPLAYER;
						positionOfType[RIGHTPLAYER] = i;
						positionOfType[CENTERPLAYER] = -1;
						countDef++;
						countCenter--;
					}
				}
				else
				{
					myTeam[i].GetBall();
				}
			}
			else if (myTeam[i].typePlayer == LEFTPLAYER)
			{
				//Dung vi tri LEFTPLAYER
				myTeam[i].StandAt(LEFTPLAYER);
			}
			else if (myTeam[i].typePlayer == DEFENCEPLAYER)
			{
				//Duoi theo bong => CENTERPLAYER
				myTeam[i].GetBall();
				myTeam[i].typePlayer = CENTERPLAYER;
				if (positionOfType[CENTERPLAYER] < 0)
					positionOfType[CENTERPLAYER] = i;
				positionOfType[DEFENCEPLAYER] = -1;
				countDef--;
				countCenter++;
			}
			else if (myTeam[i].typePlayer == RIGHTPLAYER)
			{
				//Dung vi tri RIGHTPLAYER
				myTeam[i].StandAt(RIGHTPLAYER);
			}
		}
		
	}
	else if (positionOfBall == RIGHTPLAYER)
	{
		for (i = 4; i > 0; i--)
		{
			if (myTeam[i].typePlayer == ATTACKPLAYERLEFT)
			{
				//Dung vi tri ( Khu vuc CENTERPLAYER)
				myTeam[i].StandAt(CENTERPLAYER);
				myTeam[i].typePlayer = CENTERPLAYER;
				if (positionOfType[CENTERPLAYER] < 0)
					positionOfType[CENTERPLAYER] = i;
				positionOfType[ATTACKPLAYERLEFT] = -1;
				countAttack--;
				countCenter++;
			}
			else if (myTeam[i].typePlayer == ATTACKPLAYER)
			{
				if (positionOfType[ATTACKPLAYERRIGHT] < 0)
				{
					//Dung vi tri( Khu vuc ATTACKPLAYERRIGHT)
					myTeam[i].StandAt(ATTACKPLAYERRIGHT);
					myTeam[i].typePlayer = ATTACKPLAYERRIGHT;
					positionOfType[ATTACKPLAYERRIGHT] = i;
					positionOfType[ATTACKPLAYER] = -1;
				}
				else
				{
					//Dung vi tri( Khu vuc CENTERPLAYER)
					myTeam[i].StandAt(CENTERPLAYER);
					myTeam[i].typePlayer = CENTERPLAYER;
					if (positionOfType[CENTERPLAYER] < 0)
						positionOfType[CENTERPLAYER] = i;
					positionOfType[ATTACKPLAYER] = -1;
					countAttack--;
					countCenter++;
				}
			}
			else if (myTeam[i].typePlayer == ATTACKPLAYERRIGHT)
			{
				//Dung vi tri( Khu vuc ATTACKPLAYERRIGHT )
				myTeam[i].StandAt(ATTACKPLAYERRIGHT);
			}
			else if (myTeam[i].typePlayer == CENTERPLAYER)
			{
				if (countDef == 2)
				{
					if (positionOfType[ATTACKPLAYERRIGHT] > 0 || positionOfType[ATTACKPLAYER] > 0)
					{
						//Dung vi tri ( Khu vuc CENTERPLAYER)
						myTeam[i].StandAt(CENTERPLAYER);
					}
					else
					{
						//Dung vi tri ( Khu vuc ATTACKPLAYERRIGHT)
						myTeam[i].StandAt(ATTACKPLAYERRIGHT);
						myTeam[i].typePlayer = ATTACKPLAYERRIGHT;
						if (positionOfType[ATTACKPLAYERRIGHT] < 0)
							positionOfType[ATTACKPLAYERRIGHT] = i;
						positionOfType[CENTERPLAYER] = -1;
						countAttack++;
						countCenter--;
					}
				}
				else
				{
					if (positionOfType[RIGHTPLAYER] > 0)
					{
						//Dung vi tri ( Khu vuc DEFENCEPLAYER)
						myTeam[i].StandAt(DEFENCEPLAYER);
						myTeam[i].typePlayer = DEFENCEPLAYER;
						if (positionOfType[DEFENCEPLAYER] < 0)
							positionOfType[DEFENCEPLAYER] = i;
						positionOfType[CENTERPLAYER] = -1;
						countDef++;
						countCenter--;
					}
					else
					{
						//Duoi theo bong => RIGHTPLAYER
						myTeam[i].GetBall();
						myTeam[i].typePlayer = RIGHTPLAYER;
						if (positionOfType[RIGHTPLAYER] < 0)
							positionOfType[RIGHTPLAYER] = i;
						positionOfType[CENTERPLAYER] = -1;
						countDef++;
						countCenter--;
					}
				}
			}
			else if (myTeam[i].typePlayer == LEFTPLAYER)
			{
				//Dung vi tri DEFENCEPLAYER
				myTeam[i].StandAt(DEFENCEPLAYER);
				myTeam[i].typePlayer = DEFENCEPLAYER;
				if (positionOfType[DEFENCEPLAYER] < 0)
					positionOfType[DEFENCEPLAYER] = i;
				positionOfType[LEFTPLAYER] = -1;
			}
			else if (myTeam[i].typePlayer == DEFENCEPLAYER)
			{
				if (countDef == 2 && positionOfType[RIGHTPLAYER] < 0)
				{
					//Duoi theo bong => RIGHTPLAYER
					myTeam[i].StandAt(RIGHTPLAYER);
					myTeam[i].typePlayer = RIGHTPLAYER;
					if (positionOfType[RIGHTPLAYER] < 0)
						positionOfType[RIGHTPLAYER] = i;
					positionOfType[DEFENCEPLAYER] = -1;
				}
				else
				{
					//Dung vi tri DEFENCEPLAYER
					myTeam[i].StandAt(DEFENCEPLAYER);
				}
			}
			else if (myTeam[i].typePlayer == RIGHTPLAYER)
			{
				//Duoi theo bong => RIGHTPLAYER
				myTeam[i].GetBall();
			}
		}
		
	}
	for (i = 0; i < 8; i++)
	{
		positionOfType[i] = PositionOfType((PLAYERTYPE)i);
	}

	countDef = 0;
	countAttack = 0;
	countCenter = 0;
	if (positionOfType[LEFTPLAYER] > 0)
	{
		countDef++;
	}
	if (positionOfType[RIGHTPLAYER] > 0)
	{
		countDef++;
	}
	if (positionOfType[DEFENCEPLAYER] > 0)
	{
		countDef++;
	}
	if (positionOfType[ATTACKPLAYERLEFT] > 0)
	{
		countAttack++;
	}
	if (positionOfType[ATTACKPLAYERRIGHT] > 0)
	{
		countAttack++;
	}
	if (positionOfType[ATTACKPLAYER] > 0)
	{
		countAttack++;
	}
	if (positionOfType[CENTERPLAYER] > 0)
	{
		countCenter++;
	}
	if (countAttack + countDef == 3 && ( countAttack == 1 || countDef == 1) && countCenter == 1 )
	{
	}
	else
	{
		std::cout<<"DEFENCE END  "<<countAttack<<"--"<<countCenter<<"--"<<countDef<<std::endl;
	}
}